home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7128 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: softsite.co.at!wsog
  2. Date: 15 Feb 1996 16:00:00 +0100
  3. From: wsog@softsite.co.at (Walter Sommergruber)
  4. Newsgroups: comp.lang.c
  5. Message-ID: <62ttN_YbnTB@softsite.co.at>
  6. References: <4fthhh$7th@blackice.winternet.com>
  7. Subject: Re: Watch out!  C "gotcha!"
  8. X-Newsreader: XP v3.02
  9. X-Charset: ISO-8859-1
  10. Organization: Sommergruber Software & Dienstleistungen
  11.  
  12. Michael Schwarz  (mschwarz@winternet.com) wrote on 14.02.96
  13. about "Watch out!  C "gotcha!"":
  14.  
  15. >    switch (x)
  16. >    {
  17. >       case 1:
  18. >          printf("It's 1.\n");
  19. >          break;
  20. >
  21. >       defalt:
  22. >          printf("It's not 1.\n");
  23. >          break;
  24. >    }
  25. [snip]
  26. > My point is that several compilers we tried this on compiled thismistake
  27. > with no error or warning.  If you, like so many of us, do not get enough
  28. > time to completely coverage test your code, this mistake can really bite
  29. > you on the behind.  Your "default" code will never be executed!
  30.  
  31. That's no mistake - it's valid C. "defalt:" is interpreted as a
  32. label for a potential goto. You write for instance:
  33.      case 1:
  34.         printf("abc");
  35.         if( x ) goto defalt;
  36.         printf("def");
  37.      defalt:
  38.         printf("something else");
  39.  
  40. ---                                     Take a look at ...
  41. Walter Sommergruber                                    The Software Site
  42. email: wsog@softsite.co.at           http://www.softsite.co.at/softsite/
  43.